package com.huike.web.controller.report;


import com.huike.clues.domain.vo.ClueChangeVO;
import com.huike.common.core.domain.AjaxResult;
import com.huike.business.domain.vo.BusinessChangeVO;
import com.huike.report.domain.vo.IndexVo;
import com.huike.report.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import com.huike.common.core.domain.AjaxResult;

import com.huike.report.domain.vo.IndexVo;
import com.huike.report.service.IndexVoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.List;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private IReportService reportService;


//    @GetMapping("/{beginCreateTime}/{endCreateTime}")
//    public AjaxResult getIndex(@PathVariable String beginCreateTime,
//                               @PathVariable String endCreateTime){
//        IndexVo indexVo = reportService.getIndex(beginCreateTime,endCreateTime);
//        return AjaxResult.success("操作成功",indexVo);
//    }




    /**
     * 线索转化龙虎榜
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistic(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                     @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
                                     @Param("deptId") Integer deptId){
        List<ClueChangeVO> list = reportService.salesStatistic(beginCreateTime,endCreateTime,deptId);

        return AjaxResult.success("操作成功",list);
    }



    /**
     * 商机转化龙虎榜
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                               @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
                                               @Param("deptId") Integer deptId, HttpServletResponse response){
        List<BusinessChangeVO> list = reportService.businessChangeStatistics(beginCreateTime,endCreateTime,deptId);

        return AjaxResult.success("操作成功",list);
    }



//    @Autowired
//    private IndexService indexService;

    @Autowired
    private IndexVoService indexVoService;
//
//    @GetMapping("/salesStatistic")
//    public AjaxResult leadConversion(LeadConversionDto leadConversionDto) {
//        List<LeadConversionVo> leadConversionVo = indexService.leadConversion(leadConversionDto);
//        return AjaxResult.success("操作成功", leadConversionVo);
//    }
//
//    @GetMapping("/businessChangeStatistics")
//    public AjaxResult businessChangeStatistics(LeadConversionDto leadConversionDto) {
//        List<LeadConversionVo> leadConversionVos = indexService.businessChangeStatistics(leadConversionDto);
//        return AjaxResult.success("操作成功", leadConversionVos);
//    }

    @GetMapping
    public AjaxResult index(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        IndexVo indexVo = indexVoService.getIndex(beginCreateTime, endCreateTime);
        return AjaxResult.success(indexVo);
    }

}